<?php
namespace app\common\model;
use think\Model;
use app\common\controller\Appbase;
use app\common\validate\UserFeedback as Validate;

class UserFeedback extends Model {
	
	//自动完成
	protected $update = ["reply_time"]; 
	protected function setReplyTimeAttr() {
		return date("Y-m-d H:i:s", time());
	}
	
	/**
     * 添加意见
     * @param type $data
     * @return  true
     */
	public function add($uid,$data)
    {
    	//验证
    	$validate = new Validate;
        if ( !$validate->check($data) ) {
        	$this -> errorInfo = $validate->getError();
            return false;
        }
		//保存
		$result = $this->allowField(true)->save($data);
		if(!$result){
			$this -> errorInfo = '异常错误';
			return fasle;
		}
		//返回成功通知
		return true;
    }
	
	/**
     * 回复意见
     * @param type $data
     * @return  true
     */
	public function reply($id,$data)
    {
		//保存
		$result = $this->allowField(true)->save($data,['id'=>$id]);
		//返回成功通知
		return true;
    }
	
}